import heapq
class Solution(object):
    def maxProfitAssignment(self, difficulty, profit, worker):
        """
        :type difficulty: List[int]
        :type profit: List[int]
        :type worker: List[int]
        :rtype: int
        """
        worker.sort(reverse=True)
        n = len(profit)
        job = [[-profit[i], difficulty[i]] for i in range(n)]
        heapq.heapify(job)
        m = len(worker)
        index = 0
        t = 0
        while job:
            node = heapq.heappop(job)
            while index < m and worker[index] >= node[1]:
                t += - node[0]
                index += 1
            if index == m:
                break
        return t


data = Solution()
difficulty = [2, 4, 6, 8, 10]
profit = [10, 20, 30, 40, 50]
worker = [4, 5, 6, 7]
print(data.maxProfitAssignment(difficulty, profit, worker))
